﻿using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class wappay_wappay : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void BtnAlipay_Click(object sender, EventArgs e)
    {
        DefaultAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", config.sign_type, config.alipay_public_key, config.charset, false);

        // 外部订单号，商户网站订单系统中唯一的订单号
        string out_trade_no = WIDout_trade_no.Text.Trim();

        // 订单名称 
        string subject = WIDsubject.Text.Trim();

        // 付款金额
        string total_amout = WIDtotal_amount.Text.Trim();

        // 商品描述
        string body = WIDbody.Text.Trim();

        // 支付中途退出返回商户网站地址
        string quit_url = WIDquit_url.Text.Trim();

        // 组装业务参数model
        AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
        model.Body = body;
        model.Subject = subject;
        model.TotalAmount = total_amout;
        model.OutTradeNo = out_trade_no;
        model.ProductCode = "QUICK_WAP_WAY";
        model.QuitUrl = quit_url;

        AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
        // 设置支付完成同步回调地址
        // request.SetReturnUrl("");
        // 设置支付完成异步通知接收地址
        // request.SetNotifyUrl("");
        // 将业务model载入到request
        request.SetBizModel(model);

        AlipayTradeWapPayResponse response = null;
        try
        {
            response = client.pageExecute(request, null, "post");
            Response.Write(response.Body);
        }
        catch (Exception exp)
        {
            throw exp;
        }
    }

    public class config
    {
        public config()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        // 应用ID,您的APPID
        public static string app_id = "2016102300747987";

        // 支付宝网关
        public static string gatewayUrl = "https://openapi.alipaydev.com/gateway.do";


        // 商户私钥，您的原始格式RSA私钥
        public static string private_key = "MIIEogIBAAKCAQEAhcupiXtmGU/FRXWzJhwOFRv3UwX77DnbtEbReF5bdeDrTkchSujkiQ4+ugGrVV1pt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b72IZPXi17SXodTP42CoWgST62obt2l4nacDsJ11wAEb3ZMGBoF/Wi6EEhXJPFRXVC98fS14bP/FlRg2j6RROxyGp6HKYEji/YGKe4ZyQKBgDfqCnbdZi++7qkveHCwaHij1RJTWn2giseh+er42XoaVgi4H9f+XzWpr6VYKgzzvp/wc8WZznmz7qtYsYD8LjVhbxExLqByV988eSPHZLlg5jpWQ9litOspWQzFptBF9a7BkZ1+BMfZA9zX5pGlgiGEI8Rkpjr7CIzBsMpv6+glAoGAGDTX8HgPLVMrT4gXieMwOpC1cGPiQhlDOBNOd7caDTQu3IX8Hd2vGVUskJbiQAHvAEq2g+Ngj+SMh2GnyOpLBCy19YxtcHyPHYAe9coxFwlJsE52ezsWAM4A06YwRShl8iUr/ogiNgpcXqFL3OiEUc4M3727rI4+ObnsckswzTg=";

        // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
        public static string alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmP4mMFQnvqOcnt2si64gZVgDSR6SUBtaAA6NVxH+rV4CAYSx+exa4R0yPoZGeKscAvJu3WcmLeIoReW7eF1mlZCHD0YRI1KhIvK/tfLrJqZpIaAp+D3Py3zdqQkLck51wVp+HS3wEOJfC8akDvGOfSL/WCUVeRiSAj+2QusRYyuqDTEtsfwq3aB+tlfe+W00yAOl+MDfeGNYmpfx8deRisjJieWLJJmdnPBaf3nAtOtD7texmpkDh/XyGj4CZ9eQqRy3jqoklINRl3u4yb+NGj9XJAg4pGmBzGXi2wqiyqtlDxv0hml1Vh14zNI8IcQeE/f7ve0yl9tOQEEd0fP8VQIDAQAB";

        // 签名方式
        public static string sign_type = "RSA2";

        // 编码格式
        public static string charset = "UTF-8";

        public static string return_url = "http://192.168.1.7:8023/Manage/alipay/Return_url.aspx";

    }
}